package com.xinruke.hostels.support.interfaces.api;

import com.xinruke.hostels.common.fallback.FeignFallback;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.support.interfaces.dto.SystemDictQueryDTO;
import com.xinruke.hostels.support.interfaces.dto.SystemDictQueryResultDTO;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName SupportFallback
 * @CreateDate 2019/6/17
 * @Author FengXinQiang
 * @Version V1.0.0.0
 * @Decription 基础服务API熔断
 */
@Component
public class SupportFallback implements FallbackFactory<SupportApi> {
    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private FeignFallback feignFallback;

    @Override
    public SupportApi create(Throwable throwable) {
        logger.error("系统异常", throwable);

        return new SupportApi() {
            @Override
            public ResultVO<List<SystemDictQueryResultDTO>> getSystemDictList(SystemDictQueryDTO systemDictQueryDTO) {
                return feignFallback.doFallback(SupportFallback.class, "getSystemDictList", "获取系统字典集合");
            }

            @Override
            public String getSystemDictName(String fenzubianma, String canshuzhi) {
                return "";
            }
        };
    }
}
